package com.qf.openapi.web.master.controller;

import com.qf.openapi.web.master.entity.Sys;
import com.qf.openapi.web.master.service.SysService;
import com.qf.openapi.web.master.utils.Constants;
import com.qf.openapi.web.master.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/sys")
@Slf4j
public class SysController {

    @Autowired
    private SysService sysService;

    @GetMapping("/getSysByCondition")
    public ResultVo<Sys> getSysByCondition(Integer page, Integer limit, Sys sys) {
        log.debug("收到参数,page={},limit={},sys={}", page, limit, sys);
        ResultVo<Sys> result = sysService.getSysByCondition(page, limit, sys);
        log.debug("查询结果为：resultVo={}"+result);
        return result;
    }

    @PostMapping("/add")
    public ResultVo add(Sys sys) {
        log.debug("接收到参数，sys={}", sys);
        ResultVo resultVo = sysService.addSys(sys);
        log.debug("新增结果为：resultVo={}", resultVo);
        return resultVo;
    }

    @RequestMapping("/del")
    public ResultVo del(@RequestParam("ids") List<Integer> ids) {
        log.debug("收到参数：ids={}", ids);
        ResultVo resultVo = sysService.deleteSysByIds(ids);
        log.debug("删除结果为：resultVo={}", resultVo);
        return resultVo;
    }

    @PostMapping("/update")
    public ResultVo update(Sys sys) {
        log.info("收到参数，userVo={}", sys);
        ResultVo resultVo = sysService.updateUser(sys);
        log.debug("修改结果为：resultVo={}", resultVo);
        return resultVo;
    }
}
